<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>微信小程序 | 学习笔记</title><meta name="author" content="lzoxun"><meta name="copyright" content="lzoxun"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="原生微信小程序(官方weui)  官方文档 环境1、开发环境：一般网页运行浏览器中，小程序运行微信环境中2、API差异：小程序无法调用浏览器的DOM BOM API，但是有微信环境提供的各种API3、开发模式：账号 + 微信开发者工具 （开发设置获取AppID，创建项目需要用到）  vscode开发  wxml 插件 小程序开发助手 wechat-snippit vscode编辑代码，还是微信开">
<meta property="og:type" content="article">
<meta property="og:title" content="微信小程序">
<meta property="og:url" content="http://example.com/2023/07/22/web/wechat-applet/wechat-mini-app/index.html">
<meta property="og:site_name" content="学习笔记">
<meta property="og:description" content="原生微信小程序(官方weui)  官方文档 环境1、开发环境：一般网页运行浏览器中，小程序运行微信环境中2、API差异：小程序无法调用浏览器的DOM BOM API，但是有微信环境提供的各种API3、开发模式：账号 + 微信开发者工具 （开发设置获取AppID，创建项目需要用到）  vscode开发  wxml 插件 小程序开发助手 wechat-snippit vscode编辑代码，还是微信开">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2023-07-22T07:14:09.699Z">
<meta property="article:modified_time" content="2023-07-22T07:14:09.699Z">
<meta property="article:author" content="lzoxun">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2023/07/22/web/wechat-applet/wechat-mini-app/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":true,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '微信小程序',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-07-22 15:14:09'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">108</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="学习笔记"><span class="site-name">学习笔记</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">微信小程序</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-07-22T07:14:09.699Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-07-22T07:14:09.699Z" title="更新于 2023-07-22 15:14:09">2023-07-22</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="微信小程序"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>原生微信小程序(官方weui)</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html">官方文档</a></p>
<h2 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h2><p>1、开发环境：一般网页运行浏览器中，小程序运行微信环境中<br>2、API差异：小程序无法调用浏览器的DOM BOM API，但是有微信环境提供的各种API<br>3、开发模式：账号 + 微信开发者工具 （开发设置获取AppID，创建项目需要用到）</p>
<ul>
<li>vscode开发 <ul>
<li>wxml 插件</li>
<li>小程序开发助手</li>
<li>wechat-snippit</li>
<li>vscode编辑代码，还是微信开发者工具展示(模拟器可以分离)</li>
</ul>
</li>
</ul>
<h4 id="关于"><a href="#关于" class="headerlink" title="关于"></a>关于</h4><p> 传统程序需要打包到应用商店，通过审核才能上线，小程序可以动态添加功能，无需下载，安装（绕过苹果应用商店）<br>介于H5（前端）和原生App（移动开发工程师）的产品，基本前端来开发<br>主要技术<br>    小程序原生：WXML\WXSS\JavaScript\WexinScript（只有微信能用的一些脚本）<br>    Vue开发：uni-app 跨平台选型方案（不同平台可能会有一些适配问题）<br>    React&#x2F;Vue&#x2F;Nerv：taro 京东团队的跨端跨框架技术<br>    其他开发app技术: ReactNative、Flutter(好用比较原生)。。。</p>
<h4 id="小程序-MVVM-架构思想"><a href="#小程序-MVVM-架构思想" class="headerlink" title="小程序 MVVM 架构思想"></a>小程序 MVVM 架构思想</h4><blockquote>
<p>view（.wxml）&lt;&#x3D;&gt;  ViewModel（小程序内部框架） &lt;&#x3D;&gt;  model（.js） </p>
</blockquote>
<p>小程序的架构模型(双线程模型)<br>    宿主环境（微信）为了执行小程序，将 WXML模块和WXSS样式，运行与<code>渲染层</code>，使用<code>WebView线程</code>（多个页面会有多个WebView线程）<br>    使用<code>JsCore</code>线程运行JS脚本<br>    两个线程都由<code>微信客户端（Native）</code>进行中转交互<br>    <img src= "" data-lazy-src="/../../../static/img/wx-model.jpeg" alt="双线程模型"></p>
<p>为了接近原生体验，后期可能会用 <code>flutter</code> 的 <code>Skyline 渲染引擎</code>,<code>WebView</code>渲染的最终还是一个网页</p>
<h3 id="关键字"><a href="#关键字" class="headerlink" title="关键字"></a>关键字</h3><ul>
<li>openId:openid相当重要，它是用户的唯一标识id</li>
</ul>
<h2 id="目录结构"><a href="#目录结构" class="headerlink" title="目录结构"></a>目录结构</h2><h3 id="page-文件夹"><a href="#page-文件夹" class="headerlink" title="page 文件夹"></a>page 文件夹</h3><blockquote>
<p>小程序页面, 快捷创建方式: <code>app.json</code> -&gt; <code>pages</code> -&gt; <code>直接添加路径保存</code>，就能直接生成<code>整个页面文件</code>了</p>
</blockquote>
<p>相关文件</p>
<ul>
<li><h2 id="index-js-某页面js逻辑-每个页面自己的-js"><a href="#index-js-某页面js逻辑-每个页面自己的-js" class="headerlink" title="index.js  (某页面js逻辑) -   每个页面自己的 js"></a>index.js  (某页面js逻辑)<br> -   每个页面自己的 js</h2></li>
<li><p>index.json  (某页面数据)</p>
</li>
<li><p>index.wxml  (某页面html)</p>
<ul>
<li><p>与 html 的差异</p>
</li>
<li><p>标签名称不同、属性节点不同</p>
</li>
<li><p>提供类似vue的模板语法   </p>
</li>
<li><p>wxml 采用 Mustause 语法</p>
<ul>
<li>绑定内容 : <code>&#123;&#123;xxx&#125;&#125;</code>、<code>&#123;&#123;num > 10 ? "大于十":"小于等于十"&#125;&#125;</code>、<code>&#123;&#123;num * 10&#125;&#125;</code>   绑定内容</li>
<li>绑定属性 : <code>src=&quot;&#123;&#123;xxx&#125;&#125;&quot;</code> <ul>
<li><code>hidden=&quot;&#123;&#123;bool&#125;&#125;&quot;</code> 是否隐藏元素（hidden 与 wx:if  &#x3D;&#x3D; 反 v-show 与 v-if）</li>
</ul>
</li>
</ul>
</li>
<li><p>判断语句 : <code>wx:if    wx:elif   wx:else</code></p>
</li>
<li><p>列表渲染 : <code>wx:for=&quot;&#123;&#123;List&#125;&#125;&quot;</code></p>
<ul>
<li>索引   每一项   </li>
<li><code>wx:for-index=&quot;idx&quot;</code> 重命名索引</li>
<li><code>wx:for-item=&quot;itm&quot;</code> 重命名每一项</li>
<li><code>wx:key=&quot;id&quot;</code> 自动去取item的id</li>
<li><code>wx:key=&quot;*this&quot;</code> item自身作为key</li>
</ul>
</li>
<li><p>绑定事件 : </p>
<ul>
<li>点击触发 <code>bindtap 或 bind:tap</code></li>
<li>输入触发 <code>bindinput 或 bind:input</code></li>
<li>状态改变 <code>bindchange 或 bind:change</code></li>
<li>事件对象属性<ul>
<li>target：指向触发事件的源头组件(类似 ul 事件委托的 li)</li>
<li>currentTarget：绑定事件的组件(类似 ul 事件委托的 ul)</li>
</ul>
</li>
</ul>
</li>
<li><p>事件传参</p>
<ul>
<li><p>传递参数xxx，值为123 ：<code>data-xxx=&quot;123&quot;</code></p>
</li>
<li><p>获取 <code>event.currentTarget.dataset.xxx</code></p>
</li>
<li><p>input bindinput 的最新值 <code>e.detail.value</code></p>
</li>
<li><p>传递参数xxx，值为123 ：<code>mark:xxx=&quot;123&quot;</code></p>
</li>
<li><p>获取 <code>event.mark.xxx</code></p>
</li>
</ul>
</li>
<li><p>捕获与冒泡</p>
<ul>
<li>点击后，向内捕获 到达底点击对象 向外冒泡<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--默认就是冒泡 v3tap v2tap v1tap 这样执行的--&gt;</span></span><br><span class="line"><span class="comment">&lt;!--这里设置成捕获执行v1tap v2tap v3tap--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;v1&quot;</span> <span class="attr">bindtap</span>=<span class="string">&#x27;v1tap&#x27;</span> <span class="attr">capture-bind:tap</span>=<span class="string">&quot;v1tap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;v2&quot;</span> <span class="attr">bindtap</span>=<span class="string">&#x27;v2tap&#x27;</span> <span class="attr">capture-bind:tap</span>=<span class="string">&quot;v2tap&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;v3&quot;</span> <span class="attr">bindtap</span>=<span class="string">&#x27;v3tap&#x27;</span> <span class="attr">capture-bind:tap</span>=<span class="string">&quot;v3tap&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!--到达捕获的 v2tap 时直接终止，不继续捕获和后面的向上冒泡了--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;v1&quot;</span> <span class="attr">bindtap</span>=<span class="string">&#x27;v1tap&#x27;</span> <span class="attr">capture-bind:tap</span>=<span class="string">&quot;v1tap&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;v2&quot;</span> <span class="attr">bindtap</span>=<span class="string">&#x27;v2tap&#x27;</span> <span class="attr">capture-catch:tap</span>=<span class="string">&quot;v2tap&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;v3&quot;</span> <span class="attr">bindtap</span>=<span class="string">&#x27;v3tap&#x27;</span> <span class="attr">capture-bind:tap</span>=<span class="string">&quot;v3tap&quot;</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>独特标签</p>
<ul>
<li>block 包裹多个标签，渲染后不会该标签不存在</li>
</ul>
</li>
<li><p>动态绑定class</p>
</li>
</ul>
</li>
<li><p>index.wxss  (某页面css)</p>
<ul>
<li>仅支持大部分css属性，常用的基本都支持，也有<code>自己的东西</code><ul>
<li><h2 id="rpx-适配-将宽度分为-750-份，屏幕总宽度为-750rpx-换算px-px转rpx-750-屏幕【设计稿】宽度-750屏幕-1px-1rpx-375屏幕-1px-2rpx-375和750屏幕，满屏都是750rpx-250屏幕-1px-3rpx-50屏幕-1px-15rpx-都是750rpx满屏-当拿到设计稿250的设计稿，设置设计稿上50px的盒子，就需要设置（50-3）rpx-所以屏幕越小，1px对应的rpx就越大，所以不同大小设备显示在屏幕上的比例都是一样的-rpx转px-屏幕或设计稿宽度-750"><a href="#rpx-适配-将宽度分为-750-份，屏幕总宽度为-750rpx-换算px-px转rpx-750-屏幕【设计稿】宽度-750屏幕-1px-1rpx-375屏幕-1px-2rpx-375和750屏幕，满屏都是750rpx-250屏幕-1px-3rpx-50屏幕-1px-15rpx-都是750rpx满屏-当拿到设计稿250的设计稿，设置设计稿上50px的盒子，就需要设置（50-3）rpx-所以屏幕越小，1px对应的rpx就越大，所以不同大小设备显示在屏幕上的比例都是一样的-rpx转px-屏幕或设计稿宽度-750" class="headerlink" title="rpx 适配-   将宽度分为 750 份，屏幕总宽度为 750rpx-   换算px-   px转rpx(750&#x2F;屏幕【设计稿】宽度)  &#x3D;&gt; 750屏幕 1px&#x3D;&#x3D;1rpx  &#x3D;&gt; 375屏幕 1px&#x3D;&#x3D;2rpx  &#x3D;&gt; 375和750屏幕，满屏都是750rpx-                                      250屏幕 1px&#x3D;&#x3D;3rpx &#x3D;&gt; 50屏幕 1px&#x3D;&#x3D;15rpx  &#x3D;&gt; 都是750rpx满屏-                                      当拿到设计稿250的设计稿，设置设计稿上50px的盒子，就需要设置（50*3）rpx-                                      所以屏幕越小，1px对应的rpx就越大，所以不同大小设备显示在屏幕上的比例都是一样的-   rpx转px(屏幕或设计稿宽度&#x2F;750)"></a>rpx 适配<br>-   将宽度分为 <code>750</code> 份，屏幕总宽度为 <code>750rpx</code><br>-   换算px<br>-   px转rpx(750&#x2F;屏幕【设计稿】宽度)  &#x3D;&gt; 750屏幕 1px&#x3D;&#x3D;1rpx  &#x3D;&gt; 375屏幕 1px&#x3D;&#x3D;2rpx  &#x3D;&gt; 375和750屏幕，满屏都是750rpx<br>-                                      250屏幕 1px&#x3D;&#x3D;3rpx &#x3D;&gt; 50屏幕 1px&#x3D;&#x3D;15rpx  &#x3D;&gt; 都是750rpx满屏<br>-                                      当拿到设计稿250的设计稿，设置设计稿上50px的盒子，就需要设置（50*3）rpx<br>-                                      所以屏幕越小，1px对应的rpx就越大，所以不同大小设备显示在屏幕上的比例都是一样的<br>-   rpx转px(屏幕或设计稿宽度&#x2F;750)</h2></li>
<li>@import 样式导入<ul>
<li><code>@import &quot;xxxx.wxss&quot;</code></li>
</ul>
</li>
</ul>
</li>
<li>app.wxss 全局样式表 页面中 自己的私有样式表<ul>
<li>局部权重(鼠标移入wxss类时显示权重 )大于等于全局时，就近原则，局部样式覆盖全局</li>
</ul>
</li>
</ul>
</li>
<li><p>微信的WexinScript</p>
<ul>
<li>里面的方法可以直接在双大括号中使用</li>
<li>页面中直接写 <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// wxml 页面中使用</span></span><br><span class="line">&lt;wxs <span class="variable language_">module</span>=<span class="string">&#x27;count&#x27;</span>&gt;</span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">add</span>(<span class="params">a,b</span>)&#123;  <span class="comment">//只能用原生js</span></span><br><span class="line">        <span class="keyword">return</span> a+b;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//必须使用 CommonJs导出才能使用</span></span><br><span class="line">    <span class="variable language_">module</span>.<span class="property">exports</span> = &#123;</span><br><span class="line">        <span class="attr">addvalue</span>:add</span><br><span class="line">    &#125;</span><br><span class="line">&lt;/wxs&gt;</span><br><span class="line"></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">view</span>&gt;</span>&#123;&#123;count.addvalue(1,2)&#125;&#125;<span class="tag">&lt;/<span class="name">view</span>&gt;</span></span></span><br></pre></td></tr></table></figure></li>
<li>封装到文件</li>
</ul>
 <figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// count.wxs</span></span><br><span class="line">&lt;wxs <span class="variable language_">module</span>=<span class="string">&#x27;count&#x27;</span> src=<span class="string">&#x27;/xx/xx/xx/count.wxs&#x27;</span>&gt;&lt;/wxs&gt;</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="执行"><a href="#执行" class="headerlink" title="执行"></a>执行</h3><h4 id="小程序的生命周期"><a href="#小程序的生命周期" class="headerlink" title="小程序的生命周期"></a>小程序的生命周期</h4><p><a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/reference/api/App.html">文档</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 必须再app.js中调用，且只能调用一次</span></span><br><span class="line"><span class="title class_">App</span>(&#123;</span><br><span class="line">    <span class="title function_">onLaunch</span>(<span class="params">options</span>)&#123; <span class="comment">// 只执行1次</span></span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;小程序生命周期，初始化&quot;</span>);</span><br><span class="line">        <span class="comment">// 1. 执行登录等业务逻辑</span></span><br><span class="line">        wx.<span class="title function_">login</span>(&#123;</span><br><span class="line">            <span class="attr">success</span>: <span class="function"><span class="params">res</span> =&gt;</span> &#123;</span><br><span class="line">                <span class="comment">// 发送 res.code 到后台换取 openId, sessionKey, unionId</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">        <span class="comment">//1.1 如果登录成功就将获取的数据储存到 store</span></span><br><span class="line">        <span class="comment">//1.2 只有一个，且是全局共享的，所以 共享数据可以放这里 this.globalData </span></span><br><span class="line"></span><br><span class="line">         wx.<span class="title function_">onAppRoute</span>(<span class="function">(<span class="params">res</span>) =&gt;</span> &#123;&#125; <span class="comment">// 监听全局路由跳转</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="title function_">onShow</span>(<span class="params">options</span>)&#123; <span class="comment">// 执行多次</span></span><br><span class="line">        <span class="comment">// 判断用户进入小程序的场景（群聊，扫一扫）</span></span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(options.<span class="property">scene</span>) <span class="comment">// 场景编码 主入口1001</span></span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;小程序生命周期，切换到前台&quot;</span>);</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="title function_">onHide</span>(<span class="params"></span>)&#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;小程序生命周期，切换到后台&quot;</span>);</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="attr">globalData</span>: &#123; <span class="comment">// 自定义随机对象，储存全局属性</span></span><br><span class="line">        <span class="attr">token</span>:<span class="string">&#x27;123456&#x27;</span>,</span><br><span class="line">        <span class="attr">userInfo</span>:<span class="string">&#x27;12&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="页面的生命周期"><a href="#页面的生命周期" class="headerlink" title="页面的生命周期"></a>页面的生命周期</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Page</span>(&#123;</span><br><span class="line">    <span class="comment">// 页面加载时候执行</span></span><br><span class="line">    <span class="title function_">onLoad</span>(<span class="params"></span>)&#123;</span><br><span class="line">        <span class="comment">// 获取 App 实例的共享数据</span></span><br><span class="line">        <span class="keyword">const</span> app = <span class="title function_">getApp</span>();</span><br><span class="line">        <span class="keyword">const</span> token = app.<span class="property">globalData</span>.<span class="property">token</span>; <span class="comment">// 123456</span></span><br><span class="line">        <span class="keyword">const</span> userInfo = app.<span class="property">globalData</span>.<span class="property">userInfo</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 发送请求</span></span><br><span class="line">        wx.<span class="title function_">request</span>(&#123;</span><br><span class="line">            <span class="attr">url</span>:<span class="string">&#x27;&#x27;</span>,</span><br><span class="line">            <span class="attr">success</span>: <span class="function">(<span class="params">res</span>)=&gt;</span>&#123;&#125;,</span><br><span class="line">            <span class="attr">error</span>: <span class="function">(<span class="params">err</span>)=&gt;</span>&#123;&#125;</span><br><span class="line">        &#125;)</span><br><span class="line">        <span class="comment">// 渲染数据</span></span><br><span class="line">    &#125; </span><br><span class="line">&#125;)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="组件和组件的生命周期"><a href="#组件和组件的生命周期" class="headerlink" title="组件和组件的生命周期"></a>组件和组件的生命周期</h4><p>组件的创建 components<br>    组件的 <code>.json</code> 文件  <code>component:true</code><br>    组件必须被引用，否则会报错<br>    页面的 <code>.json</code> 文件需要引入</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&quot;usingComponents&quot;</span>: &#123;</span><br><span class="line">    <span class="string">&quot;my-banner&quot;</span>:<span class="string">&quot;/components/banner/banner&quot;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>​	组件间可以<code>相互引用app.json</code> 里注册就是<code>全局注册</code> </p>
<p>组件的wxss样式<br>    组件中不能使用<code>id选择器</code>,<code>属性选择器</code>,<code>标签选择器</code> （这些选择器会影响外面页面的样式）<br>    <code>class</code> 不会影响到外面，所有尽量用class<br>    外面的处理 <code>标签</code>选择器，默认都不会影响到组件</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Components</span>(&#123;</span><br><span class="line">    <span class="attr">options</span>:&#123;</span><br><span class="line">        <span class="attr">styleIsolation</span>: <span class="string">&quot;isolated&quot;</span>， <span class="comment">// 默认</span></span><br><span class="line">        <span class="attr">styleIsolation</span>: <span class="string">&quot;apply-shared&quot;</span>， <span class="comment">// 组件中让页面样式影响到我</span></span><br><span class="line">        <span class="attr">styleIsolation</span>: <span class="string">&quot;shared&quot;</span>， <span class="comment">// 组件中让页面样式影响到我，让自己样式影响到页面</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>


<p>组件通信</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 通过组件的 properties 接收  </span></span><br><span class="line"><span class="attr">properties</span>: &#123; </span><br><span class="line">    <span class="attr">title</span>:&#123;</span><br><span class="line">        <span class="attr">type</span>:<span class="title class_">String</span>, <span class="comment">//null 不限制类型 </span></span><br><span class="line">        <span class="attr">value</span>:<span class="string">&quot;默认标题&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;,</span><br><span class="line"><span class="comment">// 组件发出自定义事件</span></span><br><span class="line"><span class="attr">methods</span>:&#123;</span><br><span class="line">    <span class="title function_">cpmClick</span>(<span class="params"></span>)&#123;</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;传出数据到外部&quot;</span>)</span><br><span class="line">        <span class="variable language_">this</span>.<span class="title function_">triggerEvent</span>(<span class="string">&quot;titleclick&quot;</span>,<span class="string">&#x27;datastrval&#x27;</span>)</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 外面 bind:titleclick=&quot;xxxxx&quot; 接收</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 接收外面传进来的累</span></span><br><span class="line"><span class="attr">externalClasses</span>:[<span class="string">&#x27;info&#x27;</span>], </span><br></pre></td></tr></table></figure>


<p>组件的生命周期</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Component</span>(&#123;</span><br><span class="line">    <span class="attr">lifetimes</span>:&#123; <span class="comment">// 组件自身的生命周期</span></span><br><span class="line">        <span class="title function_">created</span>(<span class="params"></span>) &#123; <span class="comment">// created</span></span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;组件被创建created&quot;</span>)</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="title function_">attached</span>(<span class="params"></span>) &#123; <span class="comment">// mounted</span></span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;组件被添加到组件树种attached&quot;</span>)</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="title function_">ready</span>(<span class="params"></span>) &#123;</span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;在组件视图层布局完成 ready&quot;</span>)</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="title function_">detached</span>(<span class="params"></span>) &#123; </span><br><span class="line">            <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;组件从组件树种被移除detached&quot;</span>)</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="title function_">moved</span>(<span class="params"></span>)&#123;&#125;, <span class="comment">// 组件实例被移动到家节点树的其他位置</span></span><br><span class="line">        <span class="title function_">error</span>(<span class="params"></span>)&#123;&#125; <span class="comment">// 组件方法排除错误时候  v2.4.1</span></span><br><span class="line">    &#125;,</span><br><span class="line"></span><br><span class="line">    <span class="attr">pageLifetimes</span>:&#123; <span class="comment">// 引入组件的页面的生命周期</span></span><br><span class="line">        <span class="title function_">show</span>(<span class="params"></span>)&#123;&#125;</span><br><span class="line">    &#125;,</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="小程序的登录流程"><a href="#小程序的登录流程" class="headerlink" title="小程序的登录流程"></a>小程序的登录流程</h3><p>code</p>
<ul>
<li>wx.login({success:(res)&#x3D;&gt;{res.code}) 获取</li>
<li>后端通过 code，appsecret，appid 去小程序服务器获取 openId, sessionKey, unionId </li>
<li>通过openId生成token返回给客户端</li>
</ul>
<p>openId</p>
<blockquote>
<p>用户在我的小程序中的唯一标识<br>静默登录后如果需要网页登录，需要让openid与用户账号关联</p>
</blockquote>
<p>unionId（账号同时注册小程序和公众号就会有 ）</p>
<blockquote>
<p>同一个用户在微信不同产品的唯一标识（小程序、公众号。。。）</p>
</blockquote>
<h3 id="API调用"><a href="#API调用" class="headerlink" title="API调用"></a>API调用</h3><blockquote>
<p>微信提供了专属API接口，用于网络请求: wx.request({})</p>
</blockquote>
<ul>
<li>合法域名<ul>
<li>如果小程序想要给任意服务器发送请求，需要先设置<strong>通讯域名</strong>，设置的才能通讯（开发管理-开发设置-服务器域名）</li>
<li>通讯域名（合法，ICP备案，https的域名）否则某个小程序从乱七八糟地方拿到乱七八糟的数据，影响微信用户体验</li>
<li>调试阶段可以勾选不校验合法域名，暂时使用</li>
</ul>
</li>
</ul>
<h3 id="util-文件夹"><a href="#util-文件夹" class="headerlink" title="util 文件夹"></a>util 文件夹</h3><blockquote>
<p>存放一些工具方法</p>
</blockquote>
<h3 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h3><ul>
<li>app.js  (全局js逻辑)<ul>
<li>app.js 项目入口文件</li>
</ul>
</li>
<li>app.json  (全局配置文件)<ul>
<li><code>pages</code>:小程序所有页面路径存放</li>
<li><code>windnow</code>:小程序全局窗口外观（默认标题栏，手机wifi栏，窗口背景等）</li>
<li><code>tabBar</code>: 设置底部tabBar 菜单 </li>
<li><code>&quot;style&quot;:&quot;v2&quot;</code> 用v2版本样式</li>
</ul>
</li>
<li>app.wxss  (全局css)</li>
<li>project.config.json (一些配置项目配置信息)<ul>
<li>一般不做修改</li>
<li>appid (网上的项目需要把这个appid换成自己的)</li>
</ul>
</li>
<li>project.private.config.json，（私有配置 可以放到.gitxxx里 ）覆盖 project.config.json 相同属性的值<ul>
<li>setting (详情-&gt;本地设置的操作 会更新到这里)</li>
</ul>
</li>
<li>sitemap.json (设置爬虫文件权限)</li>
</ul>
<p><a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV19r4y1N7Br?p=3&spm_id_from=pageDriver">https://www.bilibili.com/video/BV19r4y1N7Br?p=3&amp;spm_id_from=pageDriver</a></p>
<h3 id="小程序宿主环境-微信"><a href="#小程序宿主环境-微信" class="headerlink" title="小程序宿主环境 微信"></a>小程序宿主环境 微信</h3><ul>
<li>通信模型支持<ul>
<li>逻辑层 通过 微信客户端与选如此通信</li>
<li>逻辑层 通过 微信客户端与第三方服务通信 获取数据</li>
</ul>
</li>
<li>运行机制支持<ul>
<li>程序 下载代码包 -&gt; 解析 app.json 全局配置文件 -&gt; 执行app.json 小程序入口文件 -&gt; 渲染首页 启动完成</li>
<li>页面 加载解析页面的 .json 配置文件 -&gt; 加载 wxml wxss 渲染层文件 -&gt; 执行 .js 文件</li>
</ul>
</li>
<li>组件支持<ul>
<li>视图容器<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">view  <span class="comment">&lt;!--类似div--&gt;</span></span><br><span class="line">scroll-view + scroll-y属性 <span class="comment">&lt;!--可滚动的视图区域--&gt;</span></span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li>API支持<ul>
<li>事件监听API<ul>
<li>以 on 开头 监听事件触发。wx. &#x3D;&#x3D; window.</li>
</ul>
</li>
<li>同步API<ul>
<li>以 Sync 结尾的</li>
<li>结果可以直接获取，异常也会直接排除</li>
</ul>
</li>
<li>异步API<ul>
<li>通过回调接收结果</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="发布流程"><a href="#发布流程" class="headerlink" title="发布流程"></a>发布流程</h3><p><code>开发版本</code>用于程序自测，添加的测试人员都可以访问，修改完美在发布到<code>正式版本</code><br>开发者工具上传代码<br>开发版本(可以设置成体验版本)  -&gt; 审核中版本 -&gt; 线上版本</p>
<p>物料下载  - 设置 基本设置 可下载小程序二维码<br>运营数据  - 统计 或 数据助手查看(扫描右上角手机数据)</p>
<h3 id="调试工具"><a href="#调试工具" class="headerlink" title="调试工具"></a>调试工具</h3><ul>
<li>AppData  查看页面的所有数据</li>
</ul>
<h3 id="第三方包"><a href="#第三方包" class="headerlink" title="第三方包"></a>第三方包</h3><p>安装完成之后还需要 选择构建，构建npm 生成 miniprogram_npm 才能正常使用</p>
<h3 id="快捷操作"><a href="#快捷操作" class="headerlink" title="快捷操作"></a>快捷操作</h3><ul>
<li>将页面新增到编译模式，不用将页面路径移到最前面，就能直接调试指定页面了</li>
</ul>
<h2 id="小程序-云开发"><a href="#小程序-云开发" class="headerlink" title="小程序-云开发"></a>小程序-云开发</h2><ul>
<li>必须要appId</li>
<li>开发者工具新建项目(建议都选择不使用云服务)</li>
<li>进入左上角头像旁边的云开发按钮，随便输入一个合格的环境名称，提交(每个用户能申请两个，用掉后想继续用需要收费的)</li>
<li>设置权限所有用户可读</li>
</ul>
<h3 id="云数据库"><a href="#云数据库" class="headerlink" title="云数据库"></a>云数据库</h3><blockquote>
<p>采用NoSQL类型数据库</p>
</blockquote>
<h3 id="云存储"><a href="#云存储" class="headerlink" title="云存储"></a>云存储</h3><blockquote>
<p>微信小程序最大限制两M，如果有大的资源可以使用云存储解决<br>点击资源查看详情，可看到资源的id与路径</p>
</blockquote>
<h3 id="云函数"><a href="#云函数" class="headerlink" title="云函数"></a>云函数</h3><blockquote>
<p>云函数可以调用云数据库的数据，能做一些前端做不到的事情<br>客户端通过db查询有20条限制，最好通过云函数(基于nodejs)操作<br>云函数可以图片用户权限获取数据 </p>
</blockquote>
<p>操作:</p>
<ul>
<li>在根目录(pages同级)新建任意名称文件夹，如:cloudFunc</li>
<li>配置文件 project.config.json 第一级添加 “cloudfunctionRoot”:”cloudFunc”, </li>
<li>如果成功 cloudFunc会变成白云图标</li>
<li>右键新建nodejs云函数 </li>
<li>然后客户端的数据库操作都能进云函数使用</li>
<li>函数写好后，在文件夹中右键部署并上传(如果没有node_module，就选不上传node_module的)</li>
</ul>
<h4 id="内容管理"><a href="#内容管理" class="headerlink" title="内容管理"></a>内容管理</h4><blockquote>
<p>小程序数据库管理系统<br>位置:云服务 -&gt; 更多 -&gt; 内容管理 -&gt; 开通 -&gt; 得到管理系统网址<br>使用:打开网址 -&gt; 创建项目 -&gt; 进入找到内容模型(模型与数据库表对应) -&gt; 添加模板与记录 -&gt; 开发者工具数据库直接刷新</p>
</blockquote>
<h3 id="生物认证"><a href="#生物认证" class="headerlink" title="生物认证"></a>生物认证</h3><blockquote>
<p>生物认证是指通过<strong>指纹</strong>、<strong>手型</strong>、<strong>脸型</strong>、<strong>声音</strong>、<strong>虹膜和视网腊扫描</strong>等物理特征识别人的一种认证方式<br>微信目前仅支持指纹和人脸识别</p>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">lzoxun</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2023/07/22/web/wechat-applet/wechat-mini-app/">http://example.com/2023/07/22/web/wechat-applet/wechat-mini-app/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">学习笔记</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/07/22/web/wechat-applet/wechat-mini-app-2023/" title="微信小程序总结"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">微信小程序总结</div></div></a></div><div class="next-post pull-right"><a href="/2023/07/22/web/wechat-applet/wechat-play/" title="微信支付"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">微信支付</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">lzoxun</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">108</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/liaozhongxun"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/liaozhongxun" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:869664233@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">这是我的文档</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83"><span class="toc-number">1.</span> <span class="toc-text">环境</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%B3%E4%BA%8E"><span class="toc-number">1.0.1.</span> <span class="toc-text">关于</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F-MVVM-%E6%9E%B6%E6%9E%84%E6%80%9D%E6%83%B3"><span class="toc-number">1.0.2.</span> <span class="toc-text">小程序 MVVM 架构思想</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">1.1.</span> <span class="toc-text">关键字</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="toc-number">2.</span> <span class="toc-text">目录结构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#page-%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="toc-number">2.1.</span> <span class="toc-text">page 文件夹</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#index-js-%E6%9F%90%E9%A1%B5%E9%9D%A2js%E9%80%BB%E8%BE%91-%E6%AF%8F%E4%B8%AA%E9%A1%B5%E9%9D%A2%E8%87%AA%E5%B7%B1%E7%9A%84-js"><span class="toc-number">3.</span> <span class="toc-text">index.js  (某页面js逻辑) -   每个页面自己的 js</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#rpx-%E9%80%82%E9%85%8D-%E5%B0%86%E5%AE%BD%E5%BA%A6%E5%88%86%E4%B8%BA-750-%E4%BB%BD%EF%BC%8C%E5%B1%8F%E5%B9%95%E6%80%BB%E5%AE%BD%E5%BA%A6%E4%B8%BA-750rpx-%E6%8D%A2%E7%AE%97px-px%E8%BD%ACrpx-750-%E5%B1%8F%E5%B9%95%E3%80%90%E8%AE%BE%E8%AE%A1%E7%A8%BF%E3%80%91%E5%AE%BD%E5%BA%A6-750%E5%B1%8F%E5%B9%95-1px-1rpx-375%E5%B1%8F%E5%B9%95-1px-2rpx-375%E5%92%8C750%E5%B1%8F%E5%B9%95%EF%BC%8C%E6%BB%A1%E5%B1%8F%E9%83%BD%E6%98%AF750rpx-250%E5%B1%8F%E5%B9%95-1px-3rpx-50%E5%B1%8F%E5%B9%95-1px-15rpx-%E9%83%BD%E6%98%AF750rpx%E6%BB%A1%E5%B1%8F-%E5%BD%93%E6%8B%BF%E5%88%B0%E8%AE%BE%E8%AE%A1%E7%A8%BF250%E7%9A%84%E8%AE%BE%E8%AE%A1%E7%A8%BF%EF%BC%8C%E8%AE%BE%E7%BD%AE%E8%AE%BE%E8%AE%A1%E7%A8%BF%E4%B8%8A50px%E7%9A%84%E7%9B%92%E5%AD%90%EF%BC%8C%E5%B0%B1%E9%9C%80%E8%A6%81%E8%AE%BE%E7%BD%AE%EF%BC%8850-3%EF%BC%89rpx-%E6%89%80%E4%BB%A5%E5%B1%8F%E5%B9%95%E8%B6%8A%E5%B0%8F%EF%BC%8C1px%E5%AF%B9%E5%BA%94%E7%9A%84rpx%E5%B0%B1%E8%B6%8A%E5%A4%A7%EF%BC%8C%E6%89%80%E4%BB%A5%E4%B8%8D%E5%90%8C%E5%A4%A7%E5%B0%8F%E8%AE%BE%E5%A4%87%E6%98%BE%E7%A4%BA%E5%9C%A8%E5%B1%8F%E5%B9%95%E4%B8%8A%E7%9A%84%E6%AF%94%E4%BE%8B%E9%83%BD%E6%98%AF%E4%B8%80%E6%A0%B7%E7%9A%84-rpx%E8%BD%ACpx-%E5%B1%8F%E5%B9%95%E6%88%96%E8%AE%BE%E8%AE%A1%E7%A8%BF%E5%AE%BD%E5%BA%A6-750"><span class="toc-number">4.</span> <span class="toc-text">rpx 适配-   将宽度分为 750 份，屏幕总宽度为 750rpx-   换算px-   px转rpx(750&#x2F;屏幕【设计稿】宽度)  &#x3D;&gt; 750屏幕 1px&#x3D;&#x3D;1rpx  &#x3D;&gt; 375屏幕 1px&#x3D;&#x3D;2rpx  &#x3D;&gt; 375和750屏幕，满屏都是750rpx-                                      250屏幕 1px&#x3D;&#x3D;3rpx &#x3D;&gt; 50屏幕 1px&#x3D;&#x3D;15rpx  &#x3D;&gt; 都是750rpx满屏-                                      当拿到设计稿250的设计稿，设置设计稿上50px的盒子，就需要设置（50*3）rpx-                                      所以屏幕越小，1px对应的rpx就越大，所以不同大小设备显示在屏幕上的比例都是一样的-   rpx转px(屏幕或设计稿宽度&#x2F;750)</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%A7%E8%A1%8C"><span class="toc-number">4.1.</span> <span class="toc-text">执行</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">4.1.1.</span> <span class="toc-text">小程序的生命周期</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">4.1.2.</span> <span class="toc-text">页面的生命周期</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E5%92%8C%E7%BB%84%E4%BB%B6%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">4.1.3.</span> <span class="toc-text">组件和组件的生命周期</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%9A%84%E7%99%BB%E5%BD%95%E6%B5%81%E7%A8%8B"><span class="toc-number">4.2.</span> <span class="toc-text">小程序的登录流程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#API%E8%B0%83%E7%94%A8"><span class="toc-number">4.3.</span> <span class="toc-text">API调用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#util-%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="toc-number">4.4.</span> <span class="toc-text">util 文件夹</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">4.5.</span> <span class="toc-text">配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AE%BF%E4%B8%BB%E7%8E%AF%E5%A2%83-%E5%BE%AE%E4%BF%A1"><span class="toc-number">4.6.</span> <span class="toc-text">小程序宿主环境 微信</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%91%E5%B8%83%E6%B5%81%E7%A8%8B"><span class="toc-number">4.7.</span> <span class="toc-text">发布流程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B0%83%E8%AF%95%E5%B7%A5%E5%85%B7"><span class="toc-number">4.8.</span> <span class="toc-text">调试工具</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AC%AC%E4%B8%89%E6%96%B9%E5%8C%85"><span class="toc-number">4.9.</span> <span class="toc-text">第三方包</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BF%AB%E6%8D%B7%E6%93%8D%E4%BD%9C"><span class="toc-number">4.10.</span> <span class="toc-text">快捷操作</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F-%E4%BA%91%E5%BC%80%E5%8F%91"><span class="toc-number">5.</span> <span class="toc-text">小程序-云开发</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%91%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="toc-number">5.1.</span> <span class="toc-text">云数据库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%91%E5%AD%98%E5%82%A8"><span class="toc-number">5.2.</span> <span class="toc-text">云存储</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%91%E5%87%BD%E6%95%B0"><span class="toc-number">5.3.</span> <span class="toc-text">云函数</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%86%85%E5%AE%B9%E7%AE%A1%E7%90%86"><span class="toc-number">5.3.1.</span> <span class="toc-text">内容管理</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%9F%E7%89%A9%E8%AE%A4%E8%AF%81"><span class="toc-number">5.4.</span> <span class="toc-text">生物认证</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-11/" title="win 11 set">win 11 set</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-gitbash/" title="git bash">git bash</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-wsl/" title="wsl">wsl</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-main/" title="window">window</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/web/%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98/" title="兼容问题">兼容问题</a><time datetime="2023-07-22T07:14:09.699Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By lzoxun</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"></div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/haruto.model.json"},"display":{"position":"right","width":100,"height":200,"right":300},"mobile":{"show":true}});</script></body></html>